import { IPSAppDEField } from '../../app/dataentity/ipsapp-defield';
import { IPSCodeList } from '../../codelist/ipscode-list';
import { IPSControlAttribute } from '../ipscontrol-attribute';
import { IPSControlLogic } from '../ipscontrol-logic';
import { IPSControlRender } from '../ipscontrol-render';
import { IPSDEDataViewItem } from './ipsdedata-view-item';
import { IPSDEUIActionGroup } from '../../dataentity/uiaction/ipsdeuiaction-group';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEDataViewItemImpl extends PSModelObjectImpl implements IPSDEDataViewItem {
  get cLConvertMode(): 'NONE' | 'FRONT' | 'BACKEND' {
    return this.M.cLConvertMode;
  }

  protected cappslanguageres: IPSLanguageRes | null = null;

  getCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.cappslanguageres != null) return this.cappslanguageres;
    const value = this.M.getCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.cappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getCapPSLanguageRes') as IPSLanguageRes;
    return this.cappslanguageres;
  }

  get capPSLanguageRes(): IPSLanguageRes | null {
    return this.getCapPSLanguageRes();
  }

  getCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定标题语言资源');
    }
    return value;
  }

  get caption(): string {
    return this.M.caption;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dataItemName(): string {
    return this.M.dataItemName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get itemType(): 'TEXTITEM' | 'ACTIONITEM' | 'DATAITEM' {
    return this.M.itemType;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected psappdefield: IPSAppDEField | null = null;

  getPSAppDEField(): IPSAppDEField | null {
    if (this.psappdefield != null) return this.psappdefield;
    const value = this.M.getPSAppDEField;
    if (value == null) {
      return null;
    }
    this.psappdefield = this.getPSModel4('app.dataentity.IPSAppDEField', value, 'getPSAppDEField') as IPSAppDEField;
    return this.psappdefield;
  }

  get psAppDEField(): IPSAppDEField | null {
    return this.getPSAppDEField();
  }

  getPSAppDEFieldMust(): IPSAppDEField {
    const value = this.getPSAppDEField();
    if (value == null) {
      throw new Error('未指定应用实体属性');
    }
    return value;
  }

  protected pscodelist: IPSCodeList | null = null;

  getPSCodeList(): IPSCodeList | null {
    if (this.pscodelist != null) return this.pscodelist;
    const value = this.M.getPSCodeList;
    if (value == null) {
      return null;
    }
    this.pscodelist = this.getPSModel4('codelist.IPSCodeList', value, 'getPSCodeList') as IPSCodeList;
    return this.pscodelist;
  }

  get psCodeList(): IPSCodeList | null {
    return this.getPSCodeList();
  }

  getPSCodeListMust(): IPSCodeList {
    const value = this.getPSCodeList();
    if (value == null) {
      throw new Error('未指定代码表');
    }
    return value;
  }

  protected pscontrolattributes: IPSControlAttribute[] | null = null;

  getPSControlAttributes(): IPSControlAttribute[] | null {
    if (this.pscontrolattributes == null) {
      this.pscontrolattributes = this.fillChildListModel(this.M.getPSControlAttributes, 'control.IPSControlAttribute') as IPSControlAttribute[];
    }
    return this.pscontrolattributes;
  }

  get psControlAttributes(): IPSControlAttribute[] | null {
    return this.getPSControlAttributes();
  }

  findPSControlAttribute(objKey: any): IPSControlAttribute | null {
    return this.getPSModel5('control.IPSControlAttribute', this.getPSControlAttributes(), objKey) as IPSControlAttribute;
  }

  protected pscontrollogics: IPSControlLogic[] | null = null;

  getPSControlLogics(): IPSControlLogic[] | null {
    if (this.pscontrollogics == null) {
      this.pscontrollogics = this.fillChildListModel(this.M.getPSControlLogics, 'control.IPSControlLogic') as IPSControlLogic[];
    }
    return this.pscontrollogics;
  }

  get psControlLogics(): IPSControlLogic[] | null {
    return this.getPSControlLogics();
  }

  findPSControlLogic(objKey: any): IPSControlLogic | null {
    return this.getPSModel5('control.IPSControlLogic', this.getPSControlLogics(), objKey) as IPSControlLogic;
  }

  protected pscontrolrenders: IPSControlRender[] | null = null;

  getPSControlRenders(): IPSControlRender[] | null {
    if (this.pscontrolrenders == null) {
      this.pscontrolrenders = this.fillChildListModel(this.M.getPSControlRenders, 'control.IPSControlRender') as IPSControlRender[];
    }
    return this.pscontrolrenders;
  }

  get psControlRenders(): IPSControlRender[] | null {
    return this.getPSControlRenders();
  }

  findPSControlRender(objKey: any): IPSControlRender | null {
    return this.getPSModel5('control.IPSControlRender', this.getPSControlRenders(), objKey) as IPSControlRender;
  }

  protected psdeuiactiongroup: IPSDEUIActionGroup | null = null;

  getPSDEUIActionGroup(): IPSDEUIActionGroup | null {
    if (this.psdeuiactiongroup != null) return this.psdeuiactiongroup;
    const value = this.M.getPSDEUIActionGroup;
    if (value == null) {
      return null;
    }
    this.psdeuiactiongroup = this.getPSModel4('dataentity.uiaction.IPSDEUIActionGroup', value, 'getPSDEUIActionGroup') as IPSDEUIActionGroup;
    return this.psdeuiactiongroup;
  }

  get psDEUIActionGroup(): IPSDEUIActionGroup | null {
    return this.getPSDEUIActionGroup();
  }

  getPSDEUIActionGroupMust(): IPSDEUIActionGroup {
    const value = this.getPSDEUIActionGroup();
    if (value == null) {
      throw new Error('未指定界面行为组');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get valueFormat(): string {
    return this.M.valueFormat;
  }

  get enableSort(): boolean {
    return this.M.enableSort;
  }

  get cls(): string {
    return 'PSDEDataViewItemImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSControlItem' || cls == 'control.dataview.IPSDEDataViewItem') return true;
    return super.instanceof(cls);
  }
}
